#include<iostream>
#include<cstring>
using namespace std;
const int N = 1e5 + 10, M = 2 * N;
int h[N], e[M], ne[M], idx;
int son[N];
int f[N];
int n;
void add(int a, int b)
{
	e[idx] = b, ne[idx] = h[a], h[a] = idx++;
}
void dfs(int u, int fa)
{
	for (int i = h[u]; ~i; i = ne[i]) {
		int j = e[i];
		if (j == fa)continue;
		dfs(j, u);
		f[u] = max(f[u], f[j] + son[u]);
	}
}
int main()
{
	cin >> n;
	memset(h, -1, sizeof(h));
	for (int i = 2; i <= n; i++) {
		int x;
		cin >> x;
		son[x]++;
		add(i, x);
		add(x, i);
	}
	dfs(1, 0);
	cout << f[1] << endl;
	return 0;
}